//
//  TaskCompletionRateDetailVC.swift
//  SBSafetyApp
//
//  Created by Lina on 2022/11/29.
//
// 【首页-履职管理】履职报告-任务完成率详情

import Foundation
import UIKit

class TaskCompletionRateDetailVC: SubLevelViewController {
    
    let taskV = TaskCompletionRateDetailView()
    
    var modal: WdwcqkPercentModel?

    init(withDeptId deptId: Int64?, date: String, modal: WdwcqkPercentModel?) {
        super.init(nibName: nil, bundle: nil)
        self.deptId = deptId
        self.date = date
        self.modal = modal
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        title = Date.normalDateFormatter2().date(from: date)?.string(format: "yyyy年MM月")
        view.backgroundColor = .bg
        setupUI()
        
        reloadData()
    }
    
    func reloadData() {
        API.getLzglRwwcxq(withParam: RwwcxqParam(rwid: modal?.taskId, date: date, deptId: deptId)) { responseModel in
            DispatchQueue.main.async {
                print("responseModel", responseModel)
                self.taskV.updateUI(withModals: responseModel.models ?? [])
            }
        }
        
        taskV.updateItemUI(withModal: modal)
    }
    
    // MARK: - Setup
    
    func setupUI() {
        view.addSubview(taskV)
        taskV.snp.makeConstraints { make in
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
            make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
            make.left.right.equalToSuperview()
        }
    }
}
